package com.roger.match.myapplication;

import com.roger.match.library.MatchTextView;
import com.roger.match.library.util.MatchView;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.Component;
import ohos.agp.components.Slider;
import ohos.agp.components.element.ShapeElement;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class MainAbility extends Ability {
    private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0x00202, "Tag");
    private Slider mSeekBar;
    private MatchTextView mMatchTextView;
    private static final long TIME_INTERVAL = 500L;
    private static long CLICKTIME = 0L;
    private MatchDialog matchDialog;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        mMatchTextView = (MatchTextView) findComponentById(ResourceTable.Id_mMatchTextView);
        mMatchTextView.setMatchAnimateRoundListener(new MatchView.MatchAnimateRoundListener() {
            @Override
            public void onAnimateRoundFinish() {
                HiLog.info(LABEL, "onAnimateRoundFinish");
            }
        });
        mSeekBar = (Slider) findComponentById(ResourceTable.Id_mSeekBar);
        mSeekBar.setProgressValue(100);
        mSeekBar.setValueChangedListener(new Slider.ValueChangedListener() {
            @Override
            public void onProgressUpdated(Slider slider, int i, boolean b) {
                mMatchTextView.setProgress(i * 1f / 100);
                ShapeElement shapeElement = new ShapeElement();
                shapeElement.setRgbColor(RgbColor.fromArgbInt(0xFF009688));
                shapeElement.setCornerRadius(100);
                shapeElement.setAlpha(255);
                shapeElement.setShape(ShapeElement.OVAL);
                shapeElement.setBounds(0, 0, 40, 40);//动态设置圆点宽高
                mSeekBar.setThumbElement(shapeElement);
            }

            @Override
            public void onTouchStart(Slider slider) {

            }

            @Override
            public void onTouchEnd(Slider slider) {
                ShapeElement shapeElement = new ShapeElement();
                shapeElement.setRgbColor(RgbColor.fromArgbInt(0xFF009688));
                shapeElement.setCornerRadius(100);
                shapeElement.setAlpha(255);
                shapeElement.setShape(ShapeElement.OVAL);
                shapeElement.setBounds(0, 0, 35, 35);//动态设置圆点宽高
                mSeekBar.setThumbElement(shapeElement);
            }
        });
        ShapeElement shapeElement = new ShapeElement();
        shapeElement.setRgbColor(RgbColor.fromArgbInt(0xFF009688));
        shapeElement.setCornerRadius(100);
        shapeElement.setAlpha(255);
        shapeElement.setShape(ShapeElement.OVAL);
        shapeElement.setBounds(0, 0, 35, 35);//动态设置圆点宽高
        mSeekBar.setThumbElement(shapeElement);

        findComponentById(ResourceTable.Id_mButton).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (System.currentTimeMillis() - CLICKTIME > TIME_INTERVAL) {
                    matchDialog = new MatchDialog(MainAbility.this);
                    matchDialog.init(MainAbility.this);
                }
                CLICKTIME = System.currentTimeMillis();
            }
        });
    }
}
